#include <iostream>
#include "spot.h"
using namespace std;

extern int way_total;

//向数组中添加元素，NOTE不会查重@调试完成
int insert(spot spot1, spot spotarr[]){
    int temp=0;
    while(temp<=total-1){
        if(spotarr[temp]==0){
            spotarr[temp]=spot1;
            break;
        }
        temp++;
    }
    
    return 1;
};

//从数组中删除元素并用0替换@调试完成
int drop(spot spot1, spot spotarr[]){
    int temp=0;
    while(temp<=total-1){
        if(spotarr[temp]==spot1){
            spotarr[temp]=未定义;
            break;
        }
        temp++;
    }
    //空的用什么表示？？
    return 1;
};


//用于获取两点之间的代价@调试完成
int cost_simple(spot spot1,spot spot2,Distance spots[total]){
    int i=0;
    int cost=0;
    while (i <=way_total){//总之就是有几行就写几，我还没整清除怎么自动计算～
        //cout<<"fuck2";
        if(  ( (spots+i)->spot1==spot1 && (spots+i)->spot2==spot2 )  ||   ( (spots+i)->spot1==spot2 && (spots+i)->spot2==spot1 )   ){
            cost=(spots+i)->distance+(spots+i)->time+(spots+i)->money;
            break;
        };
        i++;
    }
    return cost;
};

//进行spot数组深拷贝
/*
spot *deep_copy(spot spotarr[]){
    spot *copy= new spot[total];//别问咱为啥用动态分配堆内存，问就是想折腾
    for(spot aspot : *spotarr){

    }
    return copy;//很明显还是好自为之了。。。。。
};
*/

void deep_copy(spot origin[],spot now[]){//在origin上修改，但是在now上迭代
    int count=0;
    while(count<=total-1){
        now[count]=origin[count];
        count++;//又忘记了...
    }
};

void editPath(Way pathSource[], int index,int last_index ,spot step){
    if(pathSource[index].path) {
        delete[] pathSource[index].path;
    };
    int count=0;
    pathSource[index].path=new spot[pathSource[last_index].steps+1];
    if (pathSource[last_index].steps>=1){
        while(count<=pathSource[last_index].steps-1){
            pathSource[index].path[count]=pathSource[last_index].path[count];
            count++;
        };
    }
    pathSource[index].path[pathSource[last_index].steps]=step;
    return;
    


};
